#include <iostream>
#include <unistd.h>
#include "SimpleMQTT.hpp"

char payload[] = "So this is a sample payload, isn't it?";
int main()
{
    int ret;
    SimpleMQTT::MQTTClient client;
    ret = client.init("USER001","127.0.0.1",53443,4096);
    printf("init() returned code = %d\r\n",ret);
    ret = client.startConnection(
        "127.0.0.1",1883,
        SimpleMQTT::CONNECT_CLEAN_FLAG | SimpleMQTT::CONNECT_USER_NAME_FLAG | SimpleMQTT::CONNECT_PASSWORD_FLAG | SimpleMQTT::CONNECT_WILL_FLAG,
        10,
        "willOfUSER001",
        "I'm died",
        "username",
        "password",
        10
    );
    printf("startConnection() returned code = %d\r\n",ret);
    
    ret = client.publish("a/b",(uint8_t *)payload,sizeof(payload),SimpleMQTT::QOS_LEVEL_0,0);
    printf("publish() returned code = %d\r\n",ret);

    usleep(1000000);
    printf("connection ended\r\n");
    client.endConnection();
    return 0;
}